<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
        <!-- Sidebar user panel -->
        <div class="user-panel">
            <div class="pull-left image">
                <img src="img/user2-160x160.jpg" class="img-circle" alt="User Image">
            </div>
            <div class="pull-left info">
                <p>Alexander Pierce</p>
                <a href="#"><i class="fa fa-circle text-success"></i> Online</a>
            </div>
        </div>
        <!-- search form -->
        <form action="#" method="get" class="sidebar-form">
            <div class="input-group">
                <input type="text" name="q" class="form-control" placeholder="Search...">
              <span class="input-group-btn">
                <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i>
                </button>
              </span>
            </div>
        </form>
        <!-- /.search form -->
        <!-- sidebar menu: : style can be found in sidebar.less -->
        <ul class="sidebar-menu">
            <li class="treeview <?= isset($_GET['ppid']) ? '' : 'active'; ?>" >
                <a href="index.php">
                    <i class="fa fa-dashboard"></i> <span>Dashboard</span>
                </a>
            </li>

            <?php

            if (isset($sidebar)) {
                foreach ($sidebar as $_v) {
                    ?>
                    <li class="treeview <?php if ((isset($_GET['pid']) && $_GET['pid'] == $_v['id']) || isset($_GET['ppid']) && $_GET['ppid'] == $_v['id']) {
                        print_r('active');
                    } ?>">
                        <a href="#" >
                            <i class="fa <?php echo 'fa-' . $_v['icon']; ?> "></i>
                            <span > <?php echo $_v['name']; ?> </span>
                            <i class="fa fa-angle-left pull-right"></i>
                        </a>
                        <ul class="treeview-menu" >
                            <?php
                            foreach ($_v['children'] as $item) {
                                //print_r(json_encode($item));
                                ?>
                                <?php if (count($item['children']) > 0) : ?>
                                    <li class="treeview <?php if (isset($_GET['pid']) && $_GET['pid'] == $item['id']) { print_r('active');} ?>">
                                        <a href="#" >
                                            <i class="fa  <?php echo 'fa-' . (empty($item['icon']) ? 'caret-right' : $item['icon']); ?>"></i>
                                            <?= $item['name'] ?>
                                            <i class="fa fa-angle-left pull-right"></i>
                                        </a>
                                        <ul class="treeview-menu" >
                                            <?php foreach ($item['children'] as $third_item): ?>
                                                <!-- cid 表示当前点击菜单的id -->
                                                <li class="<?php if (isset($_GET['cid']) && $_GET['cid'] == $third_item['id']) {echo 'active';} ?>">
                                                    <a href="index.php?r=<?= $third_item['url'] .'&cid=' . $third_item['id'] .  '&pid=' . $third_item['pid'] .'&ppid=' . $_v['id'] ?>">
                                                        <i class="menu-icon fa  <?php echo 'fa-' . (empty($third_item['icon']) ? 'caret-right' : $third_item['icon']); ?>"></i>
                                                        <?= $third_item['name'] ?>
                                                    </a>
                                                    <b class="arrow"></b>
                                                </li>
                                            <?php endforeach; ?>
                                        </ul>
                                    </li>
                                <?php else : ?>
                                    <li class="<?php if (isset($_GET['cid']) && $_GET['cid'] == $item['id']) {echo 'active';} ?>">
                                        <a href="index.php?r=<?= $item['url']. '&cid=' . $item['id'] . '&pid=' . $item['pid'] ?>">
                                            <i class="fa  <?php echo 'fa-' . (empty($item['icon']) ? 'caret-right' : $item['icon']); ?>"></i>
                                            <?= $item['name'] ?>
                                        </a>
                                    </li>
                                <?php endif; ?>
                            <?php } ?>
                        </ul>
                    </li>


                <?php }} ?>

        </ul>
    </section>
    <!-- /.sidebar -->
</aside>